﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BackupViewModelTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="BackupViewModelTests" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Modules.Core.Tests.Management
{
    using System;
    using Hisaab.Business.Interfaces;
    using Hisaab.Client.Common.Services;
    using Hisaab.Client.Modules.Core.Management.ViewModel;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;

    /// <summary>
    /// Defines the <seealso cref="BackupViewModelTests"/> type.
    /// </summary>
    [TestClass]
    public class BackupViewModelTests
    {
        /// <summary>
        /// Constructors the should throw exception if data manager isnull.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfDataManagerIsNull()
        {
            var session = new Mock<ISession>();
            new BackupViewModel(null, session.Object);
        }

        /// <summary>
        /// Constructors the should throw exception if session is null.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfSessionIsNull()
        {
            var dataManager = new Mock<IDataManager>();
            new BackupViewModel(dataManager.Object, null);
        }

        /// <summary>
        /// Files the name should raise property changed event.
        /// </summary>
        [TestMethod]
        public void ExportFileNameShouldRaisePropertyChangedEvent()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.ExportFilePath = "test";
            tester.AssertChange(0, "ExportFilePath");
        }

        /// <summary>
        /// Passwords the should raise property changed event.
        /// </summary>
        [TestMethod]
        public void ExportPasswordShouldRaisePropertyChangedEvent()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.ExportPassword = "test";
            tester.AssertChange(0, "ExportPassword");
        }

        /// <summary>
        /// Determines whether this instance [can Export should return false if file path is null].
        /// </summary>
        [TestMethod]
        public void CanExportShouldReturnFalseIfFilePathIsNull()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ExportFilePath = null };
            Assert.IsFalse(vm.CanExport());
        }

        /// <summary>
        /// Determines whether this instance [can Export should return false if file path is empty].
        /// </summary>
        [TestMethod]
        public void CanExportShouldReturnFalseIfFilePathIsEmpty()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ExportFilePath = string.Empty };
            Assert.IsFalse(vm.CanExport());
        }

        /// <summary>
        /// Determines whether this instance [can Export should return false if file path is white space].
        /// </summary>
        [TestMethod]
        public void CanExportShouldReturnFalseIfFilePathIsWhiteSpace()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ExportFilePath = "  " };
            Assert.IsFalse(vm.CanExport());
        }

        /// <summary>
        /// Determines whether this instance [can Export should return true if file path is non empty string].
        /// </summary>
        [TestMethod]
        public void CanExportShouldReturnTrueIfFilePathIsNonEmptyString()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ExportFilePath = "something" };
            Assert.IsTrue(vm.CanExport());
        }

        /// <summary>
        /// Files the name should raise property changed event.
        /// </summary>
        [TestMethod]
        public void ImportFileNameShouldRaisePropertyChangedEvent()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.ImportFilePath = "test";
            tester.AssertChange(0, "ImportFilePath");
        }

        /// <summary>
        /// Passwords the should raise property changed event.
        /// </summary>
        [TestMethod]
        public void ImportPasswordShouldRaisePropertyChangedEvent()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.ImportPassword = "test";
            tester.AssertChange(0, "ImportPassword");
        }

        /// <summary>
        /// Determines whether this instance [can import should return false if file path is null].
        /// </summary>
        [TestMethod]
        public void CanImportShouldReturnFalseIfFilePathIsNull()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ImportFilePath = null };
            Assert.IsFalse(vm.CanImport());
        }

        /// <summary>
        /// Determines whether this instance [can import should return false if file path is empty].
        /// </summary>
        [TestMethod]
        public void CanImportShouldReturnFalseIfFilePathIsEmpty()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ImportFilePath = string.Empty };
            Assert.IsFalse(vm.CanImport());
        }

        /// <summary>
        /// Determines whether this instance [can import should return false if file path is white space].
        /// </summary>
        [TestMethod]
        public void CanImportShouldReturnFalseIfFilePathIsWhiteSpace()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ImportFilePath = "  " };
            Assert.IsFalse(vm.CanImport());
        }

        /// <summary>
        /// Determines whether this instance [can import should return true if file path is non empty string].
        /// </summary>
        [TestMethod]
        public void CanImportShouldReturnTrueIfFilePathIsNonEmptyString()
        {
            var session = new Mock<ISession>();
            var dataManager = new Mock<IDataManager>();
            var vm = new BackupViewModel(dataManager.Object, session.Object) { ImportFilePath = "something" };
            Assert.IsTrue(vm.CanImport());
        }
    }
}